"""
Makes graphs for a directory of breakdown stats 
"""

import os
import sys
import subprocess

inputDir = sys.argv[1]
outputDir = sys.argv[2]

metric = ['edit', 'hour', 'byte']
metrics = ['edits', 'hours', 'bytes']

datatypes = ['count', 'prop']

for cohort in range(2003, 2012 + 1):

	for kind in metrics:
		
		for data in datatypes:
		
			args = ['Rscript', 'src/R/breakdown.R']

			statsfile = inputDir+'/'+ 'cohort' + str(cohort) + 'current' + '_' + data + '_' + kind + '.stat'
			outfile = outputDir + '/' + 'cohort' + str(cohort) + 'current' + '_' + data + '_' + kind + '.png'

			if os.path.isfile(statsfile):
				args.extend([statsfile, outfile, kind, data, str(cohort), 'current'])
				subprocess.call(args)
			else:
				sys.stderr.write('skipping non-existent stats file %s\n' % `statsfile`)

	
for cohort in range(2003, 2012 + 1):

	for lifespan in range(0, 2012 - cohort):

		for kind in metrics:

			for data in datatypes:

				args = ['Rscript', 'src/R/breakdown.R']

				statsfile = inputDir + '/' +'cohort' + str(cohort) + 'lifespan' + str(lifespan) + '_' + data + '_' + kind + '.stat'
				outfile = outputDir + '/' +'cohort' + str(cohort) + 'lifespan' + str(lifespan) + '_' + data + '_' + kind + '.png'
				if os.path.isfile(statsfile):
	
					args.extend([statsfile, outfile, kind, data, str(cohort), str(lifespan)])
					subprocess.call(args)
				else:
					sys.stderr.write('skipping non-existent stats file %s\n' % `statsfile`)


